package com.example.mk.UI.Mine;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mk.MainActivity;
import com.example.mk.R;
import com.example.mk.UI.Mine.data.MineDataBase;
import com.example.mk.UI.MiniApp.MiniAppActivity;
import com.example.mk.UI.Navi.NaviBarView;

import java.util.ArrayList;

import static android.content.ContentValues.TAG;

public class MineFragment extends Fragment {

    private MineViewModel mineViewModel;
    private ArrayList<MineDataBase> dataList = new ArrayList<>();

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState)
    {
        mineViewModel = new ViewModelProvider(this).get(MineViewModel.class);
        View root = inflater.inflate(R.layout.fragment_mine, container, false);
        // 设置标题栏
        NaviBarView naviBarView = root.findViewById(R.id.navi_bar_mk);
        naviBarView.setTittle("我");
        naviBarView.hideBackBtn();
        // 设置列表数据
        dataList = mineViewModel.getDataList();
        RecyclerView recyclerView = root.findViewById(R.id.list_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        MineAdapter adapter = new MineAdapter(this.getContext(), dataList, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(root.getContext(), MiniAppActivity.class);
                startActivity(intent);
                getActivity().overridePendingTransition(R.anim.nav_default_pop_enter_anim, R.anim.nav_default_pop_exit_anim);
            }
        });
        recyclerView.setAdapter(adapter);
        return root;
    }

}